﻿
using System.Data;
using Channelvn.Cached;
using Core.Library;

namespace DataObject.Members
{
    public class MembersCache
    {
        public static MembersObject Members_GetByEmail(string email)
        {
            var listParams = new object[] { email };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Members_GetByEmail", listParams);
            var fromcache = CacheController.GetCache(Constants.USER_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (MembersObject)fromcache;
            }
            else
            {
                var r = MembersController.Members_GetByEmail(email);
                CacheController.Add(Constants.USER_CACHE_CATEGORY, cacheName, r, Constants._5min);
                return r;
            }
        }

        public static MembersObject Members_GetByIdStore(int id)
        {
            var listParams = new object[] { id };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Members_GetByIdStore", listParams);
            var fromcache = CacheController.GetCache(Constants.USER_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (MembersObject)fromcache;
            }
            else
            {
                var r = MembersController.Members_GetByIdStore(id);
                CacheController.Add(Constants.USER_CACHE_CATEGORY, cacheName, r, Constants._5min);
                return r;
            }            
        }

        public static DataTable City_GetAllFrontEnd()
        {
            var listParams = new object[] { };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("City_GetAllFrontEnd", listParams);
            var fromcache = CacheController.GetCache(Constants.USER_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (DataTable)fromcache;
            }
            else
            {
                var r = MembersController.City_GetAllFrontEnd();
                CacheController.Add(Constants.USER_CACHE_CATEGORY, cacheName, r, Constants._1day);
                return r;
            }
        }


        public static string Member_HighlightHomePage_BoxNhung(int top, int round, int w, int h)
        {
            var listParams = new object[] { top, round, w , h };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Member_HighlightHomePage_BoxNhung", listParams);
            var fromcache = CacheController.GetCache(Constants.COMMENT_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (string)fromcache;
            }
            else
            {
                var r = MembersController.Member_HighlightHomePage_BoxNhung(top, round, w, h);
                CacheController.Add(Constants.COMMENT_CACHE_CATEGORY, cacheName, r, Constants._30min);
                return r;
            }  
        }

        public static DataTable Member_HighlightHomePage(int top, int round)
        {
            var listParams = new object[] { top, round };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Member_HighlightHomePage", listParams);
            var fromcache = CacheController.GetCache(Constants.COMMENT_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (DataTable)fromcache;
            }
            else
            {
                var r = MembersController.Member_HighlightHomePage(top, round);
                CacheController.Add(Constants.COMMENT_CACHE_CATEGORY, cacheName, r, Constants._30min);
                return r;
            }            
        }

        public static DataTable Members_GetList_Prev2(int round, string keyword, int pageIndex, int pageSize)
        {
            var listParams = new object[] { round, keyword, pageIndex, pageSize };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Members_GetList_Prev2", listParams);
            var fromcache = CacheController.GetCache(Constants.USER_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (DataTable)fromcache;
            }
            else
            {
                var r = MembersController.Members_GetList_Prev2(round, keyword, pageIndex, pageSize);
                CacheController.Add(Constants.USER_CACHE_CATEGORY, cacheName, r, Constants._5min);
                return r;
            }
        }

        public static DataTable Members_GetList(int round, int ordertype, string keyword, int pageIndex, int pageSize)
        {
            var listParams = new object[] { round, ordertype, keyword, pageIndex, pageSize };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Members_GetList", listParams);
            var fromcache = CacheController.GetCache(Constants.USER_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (DataTable)fromcache;
            }
            else
            {
                var r = MembersController.Members_GetList(round, ordertype, keyword, pageIndex, pageSize);
                CacheController.Add(Constants.USER_CACHE_CATEGORY, cacheName, r, Constants._5min);
                return r;
            }
        }

        public static int Members_GetList_Count_Prev2(int round, string keyword)
        {
            var listParams = new object[] { round, keyword };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Members_GetList_Count_Prev2", listParams);
            var fromcache = CacheController.GetCache(Constants.USER_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (int)fromcache;
            }
            else
            {
                int r = MembersController.Members_GetList_Count_Prev2(round, keyword);
                CacheController.Add(Constants.USER_CACHE_CATEGORY, cacheName, r, Constants._5min);
                return r;
            }
        }

        public static int Members_GetList_Count(int round, int ordertype, string keyword)
        {
            var listParams = new object[] { round, ordertype, keyword };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Members_GetList_Count", listParams);
            var fromcache = CacheController.GetCache(Constants.USER_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (int)fromcache;
            }
            else
            {
                int r = MembersController.Members_GetList_Count(round, ordertype, keyword);
                CacheController.Add(Constants.USER_CACHE_CATEGORY, cacheName, r, Constants._5min);
                return r;
            }
        }


        /// <summary>
        ///  khong dung
        /// </summary>
        /// <param name="round"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public static DataTable Members_GetByEmailFrontEnd(int round, string email)
        {
            var listParams = new object[] { round, email };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Members_GetByEmailFrontEnd", listParams);
            var fromcache = CacheController.GetCache(Constants.USER_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (DataTable)fromcache;
            }
            else
            {
                var r = MembersController.Members_GetByEmailFrontEnd(round, email);
                CacheController.Add(Constants.USER_CACHE_CATEGORY, cacheName, r, Constants._5min);
                return r;
            }
        }

        public static DataTable Members_GetByIdFrontEnd(int round, int id)
        {
            var listParams = new object[] { round, id };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Members_GetByIdFrontEnd", listParams);
            var fromcache = CacheController.GetCache(Constants.USER_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (DataTable)fromcache;
            }
            else
            {
                var r = MembersController.Members_GetByIdFrontEnd(round, id);
                CacheController.Add(Constants.USER_CACHE_CATEGORY, cacheName, r, Constants._5min);
                return r;
            }
        }

        public static DataTable Members_InSlide(int top, int round)
        {
            var listParams = new object[] {top , round };
            var cacheName = CacheHelper.CacheKey.GetCacheKey("Members_InSlide", listParams);
            var fromcache = CacheController.GetCache(Constants.USER_CACHE_CATEGORY, cacheName);
            if (fromcache != null)
            {
                return (DataTable)fromcache;
            }
            else
            {
                var r = MembersController.Members_InSlide(top, round);
                CacheController.Add(Constants.USER_CACHE_CATEGORY, cacheName, r, Constants._5min);
                return r;
            }
        }
    }
}
